package sardine.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalTime;

/**
 * @auth bruce-sha
 * @date 2015/5/21
 */
public abstract class Logs {

    final private static Logger LOG = LoggerFactory.getLogger("sardine");

    public static void console(Console console) {
        System.out.println(LocalTime.now() + " console - " + console.asString());
    }

    public static void mustLog(Console console) {
        if (LOG.isDebugEnabled()) LOG.debug(console.asString());
        else if (LOG.isErrorEnabled()) LOG.error(console.asString());
        else if (LOG.isInfoEnabled()) LOG.info(console.asString());
        else if (LOG.isTraceEnabled()) LOG.trace(console.asString());
        else if (LOG.isWarnEnabled()) LOG.warn(console.asString());
        else System.out.println(LocalTime.now() + " console - " + console.asString());
    }

    public static void log(String messageTemplate, Object... arguments) {
        if (LOG.isInfoEnabled()) LOG.info(messageTemplate, arguments);
    }

    public static void log(Console console) {
        if (LOG.isInfoEnabled()) LOG.info(console.asString());
    }

    public static void warn(String messageTemplate, Object... arguments) {
        if (LOG.isWarnEnabled()) LOG.warn(messageTemplate, arguments);
    }

    public static void warn(Console console) {
        if (LOG.isWarnEnabled()) LOG.warn(console.asString());
    }

    public static void error(String messageTemplate, Object... arguments) {
        if (LOG.isErrorEnabled()) LOG.error(messageTemplate, arguments);
    }

    public static void error(Console console) {
        if (LOG.isErrorEnabled()) LOG.error(console.asString());
    }

    public static void error(String message, Throwable t) {
        if (LOG.isErrorEnabled()) LOG.error(message, t);
    }

    public static void debug(String messageTemplate, Object... arguments) {
        if (LOG.isDebugEnabled()) LOG.debug(messageTemplate, arguments);
    }

    public static void debug(Console console) {
        if (LOG.isDebugEnabled()) LOG.debug(console.asString());
    }

    public static void main(String[] args) {
        Logs.console(() -> "123");
    }
}
